package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author chen
 * @date 2021/1/26 - 22:27 - 星期二
 * @project usian_parent
 * @package com.usian.controller
 * @by GGbomd猪猪侠
 */

/**
 * 操作购物车
 */
@RestController
public class CarController {

    @Autowired
    private CartService cartService;

    /**
     * 将购物车存放到redis缓存中
     * @param userId
     * @param cart
     * @return
     */
    @RequestMapping("/insertCart")
    public Boolean insertCart(@RequestParam String userId, @RequestBody Map<String, TbItem> cart){
        return cartService.insertCart(userId,cart);
    }

    /**
     * 根据用户 ID 查询用户购物车
     * @param userId
     * @return
     */
    @RequestMapping("/selectCartByUserId")
    public Map<String, TbItem> selectCartByUserId(@RequestParam String userId){
        return cartService.selectCartByUserId(userId);
    }

}
